TK!2
=v
#1
:n

:s
b
:c
       ***  QUADR.TK  ***
#2
:n

:s
b
:c
 Generalized Quadratic Equation Model
#4
:n
a
:v
1
:s
i
:c
)  parameters of quadratic
#5
:n
b
:s
b
:c
)  equation in general form
#6
:n
c
:v
-1
:s
o
:c
)  a*x^2 + b*x + c = 0
#7
:n
d
:v
4
:s
o
:c
discriminant
#9
:n
x1
:v
1
:s
i
:c
first real root
#10
:n
x2
:v
-1
:s
o
:c
second real root
#11
:n
xr
:s
b
:c
real part of complex root
#12
:n
xi
:s
b
:c
imaginary part  "     "  (abs value)
=u
=l
=f
#1
:n
quadratic
:c
Generalized quadratic equation solver
:t
Rule
:a
a,b,c,x1,x2,xr,xi,d
#2
:n
quadratic_woat
:c
Quadratic equation w/o absolute term
:t
Rule
:a
a,b,c,x1,x2
#3
:n
quadr_notes
:c
Notes and comments
:t
Rule
#1
:n
quadratic
:z
" Notation:
" a,b,c  - coefficients in  a*x^2 + b*x + c = 0
" x1,x2  - real roots
" xr,xi  - real component and absolute value of the imaginary component
"          of the complex conjugate roots.
"   d    - discriminant
"-------------------------------------------------------------------------
if or(known('b),k=0) then  d = b^2 - 4*a*c         " discriminant
                           k = step(d,0)           " check for complex root

if known('x1,0,1)*k then  x1 = (sqrt(d)-b)/(2*a)   " first real root
                     x1 + x2 = -b/a                " second real root
                     x1 * x2 = c/a                 " redundant equation
                 1/x1 + 1/x2 = -b/c                " redundant equation

if k=0 then xr = -b / (2*a)                " real part of complex root
if k=0 then -d = (xi*2*a)^2                " imag part of complex root
   xr^2 + xi^2 = -2*xr*c/b                 " redundant equation
    (xr*b+c)^2 = c^2 - b^2*xi^2            " redundant equation

k = known('x1,1,known('x2,1,known('xr,0,known('xi,0,k))))
/E
E
#2
:n
quadratic_woat
:z
"   Note: Inconsistency error indicates infeasible data,
"         e.g. c<>0 and x1=0 , or c=0 and x1<>0 and x2<>0 .
c = 0
if and(x1=0,x2=0) then b = 0
if and(known('x1),x1<>0) then  x2 = 0  else  a*x2 + b = 0
if and(known('x2),x2<>0) then  x1 = 0  else  a*x1 + b = 0
if and(known('a),known('b),known('x1,0,1)) then x1 = 0
/E
E
#3
:n
quadr_notes
:z
" Note: This model solves for any feasible combination of unknown roots
"       or coefficients of a quadratic equation.  The rule functions
"       'quadratic' and 'quadratic_woat' handle, respectively, equations
"       with and without an absolute (constant) term.


" Notes about "quadratic":

" 1. The function returns the values of any reasonable combination of 
"    missing argument variables, with a few limitations:
"    - Real and complex roots must not be mixed in a set of given
"      variables.
"    - xi must not be assigned zero value to imply real roots.
"    - Coefficient  b  must not be assigned non-zero value when  xr=0 .
"    - A non-zero absolute term is assumed; quadratic equations without
"      absolute term (i.e. with given c=0 or x1=0 or x2=0) may be handled
"      by function quadratic_woat.
"    - The function cannot handle linear equtions with  a=0  or  
"      x1=-c/b  or  x2=-c/b .
"    Attempts to violate these limitations lead to developing error
"    condition and terminating the solution.

" 2. The last rule with nested KNOWN functions returns  k=1 when  x1  or
"    x2  are known, and  k=0  when  xr  or  xi  are known.
/E
E
=r
#1
:r
flag = or(given('c,c=0,0),given('x1,x1=0,0),given('x2,x2=0,0))
#2
:r
if not(flag) then call quadratic(a,b,c,x1,x2,xr,xi,d)
#3
:r
if flag then call quadratic_woat(a,b,c,x1,x2)
#5
:r
" See notes in function "quadr_notes"
:s
C
=p
=t
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tv,f,0,5,0,1,0
%Of,f,2,0,0,1,0>f,0,1,0,5,0
